$(document).ready(function(){
    
});

function ownerChoose(value)
{
    if(value === 1)
    {
        $("#owner_legal_entity_wrapper").addClass('hide');
        $("#owner_citizen_wrapper").removeClass('hide');
    }else if(value === 2)
    {
        $("#owner_citizen_wrapper").addClass('hide');
        $("#owner_legal_entity_wrapper").removeClass('hide');

    }else{
        alert('Та аль нэгийг нь сонгоно уу');
    }
}

function openContractPopup()
{
    // set default to empty
    $("#contract_popup_type").val('');
    $("#contract_target_register").val('');
    $("#contract_name").val('');
    $("#contract_signed_date").val('');
    $("#contract_begin_date").val('');
    $("#contract_end_date").val('');
    $("#contract_description").val('');
    $("#contract_description").html('');
    
}

function addContract()
{
    
    $.ajax({
            type: 'post',
            url: '/contract/saveAjax/',
            data: {
                contractPopupType : $("#contract_popup_type").val(),
                contractTargetRegister : $("#contract_target_register").val(),
                contractName : $("#contract_name").val(),
                contractSignedDate : $("#contract_signed_date").val(),
                contractBeginDate : $("#contract_begin_date").val(),
                contractEndDate : $("#contract_end_date").val(),
                contractDescription : $("#contract_description").val()
                
            },
            beforeSend: function(){
                $.blockUI({ message: null });
            },
            dataType: "json",
            success: function (result) {
                
                if(result.status === 'success')
                {
                    $("#credit_contract_number").html(result.data.html);
                    $("#credit_contract_number").select2("val", result.data.id);
                }else{
                    
                }
            },
            error: function () {
                $.unblockUI();
                $('#contractPopup').modal('hide');
            }
        }).done(function(){
            $.unblockUI();
            $('#contractPopup').modal('hide');
        });
    
    
    
    
    
}